package com.CMC.yhdeng;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ScoreDataAdapter extends ArrayAdapter<ScoreData> {
	public class ViewHolder{
		public View vTitle, vDate, vTotleScore, vScore, vTestingTime, vSpendingTime;

		public ViewHolder(View vTitle, View vDate, View vTotleScore,
				View vScore, View vTestingTime, View vSpendingTime) {
			super();
			this.vTitle = vTitle;
			this.vDate = vDate;
			this.vTotleScore = vTotleScore;
			this.vScore = vScore;
			this.vTestingTime = vTestingTime;
			this.vSpendingTime = vSpendingTime;
		}
		
	}
	
	LayoutInflater inflater;
	ArrayList<ScoreData> lstScoreData;
	public ScoreDataAdapter(Context context, int resource,
			int textViewResourceId, List<ScoreData> objects) {
		super(context, resource, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
	}

	public ScoreDataAdapter(Context context, int resource,
			int textViewResourceId, ScoreData[] objects) {
		super(context, resource, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
	}

	public ScoreDataAdapter(Context context, int resource,
			int textViewResourceId) {
		super(context, resource, textViewResourceId);
		// TODO Auto-generated constructor stub
	}

	public ScoreDataAdapter(Context context, int textViewResourceId,
			ScoreData[] objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
	}

	public ScoreDataAdapter(Context context, int textViewResourceId, List<ScoreData> lst) {
		super(context, textViewResourceId);
		inflater =LayoutInflater.from(context);
		lstScoreData=(ArrayList<ScoreData> )lst;
		// TODO Auto-generated constructor stub
	}

	
	

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		 View rowView = convertView;
		    // reuse views
		    if (rowView == null) {
		      
		      rowView = inflater.inflate(R.layout.listview_item_style, null);
		      // configure view holder
		      
		      ViewHolder vh=new ViewHolder(rowView.findViewById(R.id.tvLastQuizRecord), 
		    		  rowView.findViewById(R.id.textView2), 
		    		  rowView.findViewById(R.id.textView3),
		    		  rowView.findViewById(R.id.textView4),
		    		  rowView.findViewById(R.id.textView5),
		    		  rowView.findViewById(R.id.textView6));
		      rowView.setTag(vh);
		      
		    }

		    ViewHolder vh=(ViewHolder )rowView.getTag();
		    // fill data
		    ScoreData sd= lstScoreData.get(position);
		    
		    TextView tv=(TextView )vh.vTitle;
		    tv.setText(sd.getTitle());

		    tv=(TextView )vh.vDate;
		    tv.setText(sd.finsih_datetime);
		    
		    tv=(TextView )vh.vTotleScore;
		    tv.setText("100");
		    
		    tv=(TextView )vh.vScore;
		    tv.setText(sd.score.toString());
		    
		    tv=(TextView )vh.vTestingTime;
		    tv.setText(sd.exam_default_time.toString());
		    
		    tv=(TextView )vh.vSpendingTime;
		    tv.setText(sd.exam_time.toString());
		    return rowView;
	}

	@Override
	public int getCount() {
		
		return lstScoreData.size();
	}

	@Override
	public ScoreData getItem(int position) {
		
		return lstScoreData.get(position);
	}
	
	

}
